use reqwest;
use crate::bochu_monitor::shutdown_start_times_info::collect_shutdown_start_times;

pub async fn upload_shutdown_start_times() -> Result<(), Box<dyn std::error::Error>> {
    let shutdown_start = collect_shutdown_start_times()?;

    // 将 JSON 数据转换为字符串
    let json_data = serde_json::to_string(&shutdown_start)?;

    // 创建 HTTP 客户端并发送数据
    let client = reqwest::Client::new();
    let response = client
        .post("https://ocs.fscut.com/api/receive/clientEfficiency")
        .header("Content-Type", "application/json")
        .body(json_data)
        .send()
        .await?;

    println!("Response: {:?}", response.status());

    if response.status().is_success() {
        println!("Shutdown/start times successfully uploaded.");
    } else {
        eprintln!("Failed to upload shutdown/start times.");
    }

    Ok(())
}
